import qs from 'qs' // 根据需求是否导入qs模块
import $http from "axios"
import url from '@/api/base'
import store from '../store/index'
import utils from '@/utils/index'
const timeAjax = utils.timeFormate()
const fromatPushTime = utils.fromatPushTime()
const monthDay = utils.monthDay()
const getTime = utils.getTime()
/**
 * auth Json数据
 */
export function authJson(url) {
  return $http({
    url: url,
    method: 'get',
  })
}
/**
 * 江苏Json数据
 */
export function jSJson(url) {
  return $http({
    url: url,
    method: 'get',
  })
}

/**
 * 
 * @param {手机号码} phone 
 */
export function getUserIdByPhone(phone) {
  return $http({
    url: url.baseUrl217 + "/getUserIdByPhone",
    method: 'post',
    params: {
      inParam: {
        "sysCode": "FH_PUBOPE",
        "phone": phone,
        "time": getTime,
        "userType": "5"
      }
    }
  })
}
/**
 * 
 * @param {id} userId 
 * @param {密码} pwd 
 */
export function upDatePwd(userId, pwd) {
  return $http({
    url: url.baseUrl217 + "/updatePwd",
    method: 'post',
    params: {
      inParam: {
        "sysCode": "FH_PUBOPE",
        "userId": userId,
        "time": getTime,
        "password": pwd
      }
    }
  })
}
/**
 * 
 * @param {手机号码} phone 
 */
export function sendMessage(phone) {
  return $http({
    url: "http://dz.enjoy-reading.cn:8082/fhbook/userhead/selectMD5",
    method: 'post',
    params: {
      "mobiles": phone,
      "time": getTime,
    }
  })
}
/**
 * 登陆  zxx1     123456
 */
export function login(userZch, password) {
  return $http({
    url: url.baseUrl217 + "/login",
    method: 'post',
    params: {
      inParam: {
        "sysCode": "FH_PUBOPE",
        "time": timeAjax,
        "userZch": userZch,
        "password": password,
        // 农家 4 
        "userType": "5"
      }
    }
  })
}
/** 
 * 获取用户信息
 */
export function selectUserhead() {
  return $http({
    url: url.localUrl + "/userhead/selectUserhead",
    method: 'post',
    params: {
      userid: store.state.user.userId
    }
  })
}

/**
 * 首页资源
 */
export function index(resCount) {
  return $http({
    url: url.baseUrl217 + "/getRecommendedResourcesList",
    method: 'post',
    params: {
      inParam: {
        "sysCode": "FH_PUBOPE",
        "resCount": resCount || "6",
        "prePushTime": fromatPushTime,
        "time": timeAjax,
        "userId": sessionStorage.getItem('userId') || "33277",
      }
    }
  })
}
/**
 * 首页公告
 */
export function notice(page, pageSize) {
  return $http({
    url: url.baseUrl217 + "/queryNoticeList",
    method: 'post',
    params: {
      inParam: {
        time: timeAjax,
        sysCode: 'FH_PUBOPE',
        accId: sessionStorage.getItem('accId') || "3",
        orgId: sessionStorage.getItem('orgId') || "25",
        terminalType: '2',
        callType: 1,
        currentPage: page || 1,
        pageSize: pageSize || 10
      }
    }
  })
}
/**
 * 首页最新上架
 */
export function newsColum(resCount) {
  return $http({
    url: url.baseUrl217 + "/getNewColumResByColumnId",
    method: 'post',
    params: {
      inParam: {
        "time": timeAjax,
        "sysCode": "FH_PUBOPE",
        "resCount": resCount || "6",
        "columnId": sessionStorage.getItem('BookColumnId'),
        "accId": sessionStorage.getItem("accId"),
        "orgId": sessionStorage.getItem("orgId"),
        "terminalType": "10"
      }
    }
  })
}
/**
 * 首页专题活动
 */
export function activitiesList(page, pageSize) {
  return $http({
    url: url.baseUrl217 + "/getSpecialActivitiesList",
    method: 'post',
    params: {
      inParam: {
        "sysCode": "FH_PUBOPE",
        "accId": sessionStorage.getItem("accId") || "3",
        "pageSize": pageSize,
        "time": timeAjax,
        "currentPage": page,
        "userId": sessionStorage.getItem("userId") || "19",
        "orgId": sessionStorage.getItem("orgId")
      }
    }
  })
}
/**
 * 
 * @param {类型} type 
 * @param {位置} ads 
 */
export function banner(type,ads) {
  return $http({
    url: 'http://180.97.46.217/fh_pubDucResServer/rest' + "/queryAdvertisingList",
    method: 'post',
    params: {
      inParam: {
        "time": timeAjax,
        "accId": sessionStorage.getItem("accId"),
        "advertisingType": type,
        "platformId": "10",
        "time": timeAjax,
        "advertisingPosition": ads,
        "sysCode": "FH_PUBOPE"
      }
    }
  })
}
/**
 * 广告数据
 */
export function advList() {
  return $http({
    url: 'http://180.97.46.217/fh_pubDucResServer/rest' + "/queryAdvertisingList",
    method: 'post',
    params: {
      inParam: {
        // "accId": sessionStorage.getItem('accId') || "3",
        "time": timeAjax,
        "accId": "30",
        "advertisingType": "3",
        "platformId": "10",
        "time": timeAjax,
        "advertisingPosition": "4",
        "sysCode": "FH_PUBOPE"
      }
    }
  })
}
/**
 * 获取一级分类
 */
export function getFirstLevel() {
  return $http({
    url: url.baseUrl217 + "/getFirstLevelColumnList",
    method: 'post',
    params: {
      inParam: {
        "time": timeAjax, //调用时间
        "sysCode": "FH_PUBOPE",
        "terminalType": '1',
        "accId": sessionStorage.getItem('accId') || "3",
        "userId": sessionStorage.getItem('userId') || "19"
      }
    }
  })
}
/**
 * 获取图书分类
 * getColumnNameByFColumnId
 */
export function getColumnName(columnId) {
  return $http({
    url: url.baseUrl217 + "/getColumnNameByFColumnId",
    method: 'post',
    params: {
      inParam: {
        time: timeAjax, //调用时间
        sysCode: "FH_PUBOPE",
        terminalType: '1',
        // userId: sessionStorage.getItem('userId') || "19",
        accId: sessionStorage.getItem('accId'),
        orgId: sessionStorage.getItem('orgId'),
        columnId: columnId,
      }
    }
  })
}
/**
 * 获取图书列表
 * getColumnNameByFColumnId
 */
export function getBookList(page, pageSize) {
  return $http({
    url: url.baseUrl217 + "/getColumResByColumnId",
    method: 'post',
    params: {
      inParam: {
        "sysCode": "FH_PUBOPE",
        "columnId": store.state.columnId || "3",
        "accId": sessionStorage.getItem('accId') || "3",
        "pageSize": pageSize || "10",
        "time": timeAjax,
        "currentPage": page,
        "terminalType": "1"
      }
    }
  })
}
export function getVideoList1(columnId,page, pageSize) {
  return $http({
    url: url.baseUrl217 + "/getColumResByColumnId",
    method: 'post',
    params: {
      inParam: {
        "time": "2018-12-27 19:14:31",
        "sysCode": "FH_PUBOPE",
        "columnId": columnId,
        "userId": sessionStorage.getItem('userId'),
        "terminalType": 1,
        "accid": sessionStorage.getItem('accId'),
        "currentPage": 1,
        "pageSize": 10
      }
    }
  })
}
/**
 * 获取期刊二级
 * getCnkiGroupInformation
 */
export function getPeriodicalType(page, pageSize) {
  return $http({
    url: url.baseUrl217 + "/getCnkiGroupInformation",
    method: 'post',
    params: {
      inParam: {
        "sysCode": "FH_PUBOPE",
        "maxvalue": [],
        "pageSize": pageSize || "100",
        "constraint": [],
        "time": timeAjax,
        "currentPage": page || "1",
        "userId":  sessionStorage.getItem("userId") || "19",
        "resourceType": "5",
        "group": ["type_name"]
      }
    }
  })
}
/**
 * 获取期刊分类详情
 * getCnkiGroupInformation
 */
export function getperiodicalListList(page, pageSize) {
  return $http({
    url: url.baseUrl217 + "/getCnkiGroupInformation",
    method: 'post',
    params: {
      inParam: {
        "sysCode": "FH_PUBOPE",
        "maxvalue": ["period", "unit", "file_name"],
        "pageSize": pageSize || 20,
        "constraint": [{
          "name": "type_name",
          "value": store.state.columnId
        }],
        "time": timeAjax,
        "currentPage": page || 1,
        "userId": sessionStorage.getItem("userId") || "19",
        "resourceType": "5",
        "group": ["source"]
      }
    }
  })
}
/**
 * 获取报纸列表
 */
export function getNewspaperList(page, pageSize) {
  return $http({
    url: url.baseUrl217 + "/getCnkiGroupInformation",
    method: 'post',
    params: {
      inParam: {
        group: ["paper_name"],
        constraint: [],
        time: timeAjax,
        userId: sessionStorage.getItem("userId"),
        pageSize: pageSize || "20",
        allLoaded: false,
        currentPage: page || "1",
        resourceType: 4,
        maxvalue: ["date", "file_name"],
        sysCode: "FH_PUBOPE"
      }
    }
  })
}
/**
 * 获取视频分类
 */
export function getVideoList() {
  return $http({
    url: url.videoUrl + "/getCnkiGroupInformation",
    method: 'post',
    params: {
      inParam: {
        "terminalType": "8",
        "accId": sessionStorage.getItem("accId") || "3",
        "time": timeAjax,
        "maxvalue": [],
        "userId": sessionStorage.getItem("userId"),
        "pageSize": 100,
        "constraint": [],
        "currentPage": 1,
        "group": ["type_name"],
        "sysCode": "FH_PUBOPE",
        "resourceType": "7"
      }
    }
  })
}
/**
 * 获取视频分类2
 */
export function getNewVideoTwoList(page, pageSize) {
  return $http({
    url: url.baseUrl217 + "/getCnkiGroupInformation",
    method: 'post',
    params: {
      inParam: {
        terminalType: '8',
        accId: sessionStorage.getItem('accId') || "3",
        time: timeAjax,
        maxvalue: ['file_name'],
        userId: sessionStorage.getItem('userId'),
        pageSize: pageSize || 10,
        constraint: [{
          "name": "type_name",
          "value": store.state.columnId
        }],
        currentPage: page || 1,
        group: ['book_type_code_name'],
        sysCode: 'FH_PUBOPE',
        resourceType: '7'
      }
    }
  })
}
/**
 * 搜索 
 */
export function search(keyWord, resKind, page, pageSize) {
  return $http({
    url: url.baseUrl217 + "/search",
    method: 'post',
    params: {
      inParam: {
        time: timeAjax,
        sysCode: "FH_PUBOPE",
        userId: sessionStorage.getItem("userId") || "19",
        terminalType: 1,
        accId: sessionStorage.getItem("accId") || "3",
        keyWord: keyWord,
        resKind: resKind,
        currentPage: page || 1,
        pageSize: pageSize || 10
      }

    }
  })
}
/**
 * 获取悦读列表
 */
export function geReadList(page, pageSize,columnId) {
  return $http({
    url: url.baseUrl217 + "/getColumResByColumnId",
    method: 'post',
    params: {
      inParam: {
        accId: sessionStorage.getItem('accId') || "3",
        currentPage: page || 1,
        terminalType: 1,
        columnId: columnId||12,
        time: timeAjax, //调用时间
        pageSize: pageSize || 10,
        sysCode: "FH_PUBOPE"
      }
    }
  })
}
/**
 * 获取悦读详情
 */
export function geReadInfo(articleId) {
  return $http({
    url: url.localUrl + "/article/selectContent",
    method: 'post',
    params: {
      articleId: articleId
    }
  })
}
/**
 * 获取共享悦读详情
 */
export function geShareReadInfo(articleId) {
  return $http({
    url: url.localUrl + "/article/selectContentOne",
    method: 'post',
    params: {
      articleId: articleId
    }
  })
}
/**
 * 获取活动详情
 */
export function geActivityInfo(activityId) {
  return $http({
    url: url.localUrl + "/activity/selectContent",
    method: 'post',
    params: {
      activityId: activityId
    }
  })
}
/**
 * 月排行榜 
 * /readrecord/selectMonthRankings
 */
export function monthRankings(pageNo, pageSize) {
  return $http({
    url: url.localUrl + "/readrecord/selectMonthRankings",
    method: 'post',
    params: {
      startDate: monthDay.firstDay,
      endDate: monthDay.lastDay,
      pageNo: pageNo || 1,
      pageSize: pageSize || 8,
      edition: sessionStorage.getItem("accId") || "3"
    }
  })
}
/**
 * 收藏排行榜
 * /readrecord/selectCollectionRankings
 */
export function collectionRankings(pageNo, pageSize) {
  return $http({
    url: url.localUrl + "/readrecord/selectCollectionRankings",
    method: 'post',
    params: {
      pageNo: pageNo || 1,
      pageSize: pageSize || 8,
      edition: sessionStorage.getItem("accId") || "3"
    }
  })
}
/**
 * 好书推荐排行榜
 * /readrecord/selectRankings
 */
export function selectRankings(pageNo, pageSize) {
  return $http({
    url: url.localUrl + "/readrecord/selectRankings",
    method: 'post',
    params: {
      pageNo: pageNo || 1,
      pageSize: pageSize || 8,
      edition: sessionStorage.getItem("accId") || "3"
    }
  })
}
/**
 * 修改用户信息
 * /userhead/updateWebUserhead用户信息
 * userid  username sex birthDay  cityCode   areaCode    describ 
 */
export function updateWebUserhead(username, sex, birthDay, cityCode, areaCode, describ) {
  let params = new URLSearchParams();
  params.append('userid', sessionStorage.getItem("userId") || "19");
  params.append('userName', username);
  params.append('sex', sex);
  params.append('birthDay', birthDay);
  params.append('cityCode', cityCode);
  params.append('areaCode', areaCode);
  params.append('describ', describ);
  return $http({
    url: url.localUrl + "/userhead/updateWebUserhead",
    method: 'post',
    params: params
  })
}
/** 
 * 根据id  修改头像
 */
export function uploadWebUserhead(data) {
  // console.log(content)
  return $http({
    url: url.localUrl + "/userhead/uploadWebUserhead",
    method: 'post',
    data: data,
    headers: {
      'Content-Type': 'multipart/form-data;charset=utf-8',
      "Content-Type": "application/json"
    }
  })
}
/** 
 * 是否加入收藏\书架
 * type 默认1 或者 o
 */
export function isCollect(bookId, columnType) {
  // console.log(content)
  const params = new URLSearchParams();
  params.append("columnType", columnType || 1);
  params.append("type", 0);
  params.append("userid", sessionStorage.getItem("userId") || "19");
  params.append("fileid", bookId);
  params.append("edition", sessionStorage.getItem("accId") || "3");
  return $http({
    url: url.localUrl + "/readrecord/selectBookMessage",
    method: 'post',
    data: params
  })
}
/**
 * 
 * @param {收藏类型} columntype 
 * @param {封面} cover 
 * @param {名称} name 
 * @param {描述} describe 
 * @param {id} fileid 
 */
export function addCollect(columntype, cover, name, describe, fileid) {
  // console.log(content)
  const params = new URLSearchParams();
  params.append("userid", sessionStorage.getItem("userId") || "19");
  //收藏类型 例如：1 图书 2期刊 3 报纸 7视听 ...
  params.append("columntype", columntype || 1);
  //封面
  params.append("cover", cover||'');
  //名称
  params.append("name", name||'');
  //类型 1 图书 2 期刊  3 报纸  ....
  params.append("type", 1);
  //描述
  params.append("describe", describe||'1');
  //播放数量
  params.append("playback", 0);
  //fileid 唯一值不能重复
  params.append("fileid", fileid);
  params.append("edition", sessionStorage.getItem("accId") || "3");
  return $http({
    url: url.localUrl + "/collection/addCollection",
    method: 'post',
    data: params
  })
}
/**
 * 删除收藏
 * @param {查询出来的收藏id} collectionId 
 */
export function delCollect(collectionId) {
  return $http({
    url: url.localUrl + "/collection/deleteCollection",
    method: 'post',
    params: {
      id: collectionId
    }
  })
}
/**
 * 添加阅读记录
 * @param {资源名称} bookName 
 * @param {资源类别} type 
 * @param {资源id} bookId 
 * @param {资源描述} describ 
 * @param {资源封面} cover 
 * @param {资源作者} author 
 */
export function readRecord(bookName, type, bookId, describ, cover, author) {
  const params = new URLSearchParams();
  params.append("title", bookName);
  params.append("type", type);
  params.append("userid", sessionStorage.getItem("userId") || "19");
  params.append("fileid", bookId);
  params.append("recorddate", "");
  params.append("describ", describ);
  params.append("imgurl", cover||'');
  params.append("author", author);
  params.append("edition", sessionStorage.getItem('accId') || "3");
  return $http({
    url: url.localUrl + "/readrecord/addReadrecord",
    method: 'post',
    data: params
  })
}
/**
 * 我的收藏
 */
export function myCollect(columntype, pageNo, pageSize) {
  return $http({
    url: url.localUrl + "/collection/selectCollection",
    method: 'post',
    params: {
      userid: sessionStorage.getItem("userId") || "19",
      pageNo: pageNo || 1,
      columntype: columntype || 1,
      pageSize: pageSize || 16
    }
  })
}
/**
 * 我的书架
 * /bookshelf/selectBookShelf
 */
export function bookShelf(pageNo, pageSize) {
  return $http({
    url: url.localUrl + "/bookshelf/selectBookShelf",
    method: 'post',
    params: {
      userid: sessionStorage.getItem("userId") || "19",
      pageNo: pageNo || 1,
      pageSize: pageSize || 16
    }
  })
}
/**
 * 添加到书架
 * @param {描述} describe 
 * @param {封面} cover 
 * @param {书名} title 
 * @param {作者} author 
 * @param {唯一id} fileid 
 */
export function addbooks(describe, cover, title, author, fileid) {
  const params = new URLSearchParams();
  params.append("userid", sessionStorage.getItem("userId"));
  params.append("describe", describe);
  params.append("cover", cover);
  params.append("title", title);
  params.append("author", author);
  //fileid 唯一值不能重复
  params.append("fileid", fileid);
  return $http({
    url: url.localUrl + "/bookshelf/addBookShelf",
    method: 'post',
    data: params
  })
}

/**
 * 移除书架
 * /bookshelf/deleteBookShelf
 */
export function deleteBookShelf(bookShelfId) {
  return $http({
    url: url.localUrl + "/bookshelf/deleteBookShelf",
    method: 'get',
    params: {
      id: bookShelfId
    }
  })
}
/**
 * 阅读记录
 * /bookshelf/selectBookShelf
 */
export function selectReadRecord(pageNo, pageSize) {
  return $http({
    url: url.localUrl + "/readrecord/selectReadrecord",
    method: 'post',
    params: {
      userid: sessionStorage.getItem("userId") || "19",
      edition: sessionStorage.getItem("accId") || "3",
      pageNo: pageNo || 1,
      pageSize: pageSize || 20
    }
  })
}
/**
 * 共享资源
 * getOrgResByOrgIdAndResType
 */
export function getOrgResByOrgIdAndResType(resType,pageNo, pageSize) {
  return $http({
    url: url.baseUrl217 + "/getOrgResByOrgIdAndResType",
    method: 'post',
    params: {
      inParam: {
        "sysCode": "FH_PUBOPE",
        "resType": resType||1,
        "pageSize": pageSize ||"10",
        "time": timeAjax,
        "currentPage": pageNo || 1,
        "orgId": sessionStorage.getItem('orgId'),
      }
    }
  })
}
